<?php
namespace Admin\Controller;
use Think\Controller;

/**
 * 登录、注销等功能
 * @author  Zou Yiliang
 * @since   1.0
 */
class DefaultController extends Controller
{

    public function login()
    {
        //处理登录请求
        if (!empty($_POST)) {

            $name=$_POST['name'];
            $password=$_POST['password'];
            $data['username']=htmlspecialchars($username);
            $data['pwd']=md5(htmlspecialchars($password));
            $data['status']=10;
            $adminmodel=M('admin');
            $list=$adminmodel->where($data)->find();

            if (!empty($list)) {
                //登录成功
                $_SESSION['admin']['username']=$list['name'];
                $returnUrl = session('returnUrl');
                if (!empty($returnUrl)) {
                    //登录拦截时记录的url (哪里来，回哪里)
                    header('Location:' . $returnUrl);
                    unset($_SESSION['returnUrl']);
                } else {
                    //跳去admin的首页
                    $this->redirect('Index/index');
                }
                return;
            }

            $this->assign('message', '用户名或密码不匹配');
        }

        //显示登录界面
        $this->display();
    }
    public function loginout(){
        unset($_SESSION['admin']['username']);
        $this->redirect('Default/login');
    }

}
